//
//  ByUIMineSelectIDVC.m
//  chequanbao_ios
//
//  Created by mc on 2017/5/23.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIMineSelectIDVC.h"


@interface ByUIMineSelectIDVC ()
@property (nonatomic, strong) UIScrollView *scroll;

@end

@implementation ByUIMineSelectIDVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"推广中心";
    [self addLeftBackBarButtonItem];
    [self createViews];
}
#pragma mark -- getter
- (UIScrollView *)scroll {
    
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
        _scroll.showsVerticalScrollIndicator = NO;
        _scroll.bounces = NO;
        [self.view addSubview:_scroll];
    }
    return _scroll;
}

#pragma mark -- 创建视图
- (void)createViews {
    
    CGFloat x, y, width, height;
    CGFloat margin_h = 40, margin_v = 20;
    
    NSArray *titles = @[@"我是店长",@"联盟商家", @"创业伙伴",@"城市服务中心",@"省管理中心"];
 
    for (int i = 0; i < titles.count; i ++) {
        
        width = SCREEN_WIDTH - margin_h * 2;
        height = width /4;
        x = margin_h;
        y = (margin_v + height) * i + 20;
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
        bgView.backgroundColor = [UIColor colorWithRed:95/255.0 green:110/255.0 blue:170/255.0 alpha:0.4];
        bgView.tag = i;
        bgView.layer.cornerRadius = 4.0;
        [self.scroll addSubview:bgView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (bgView.height - 30)/2, width, 30)];
        titleLabel.text = titles[i];
        titleLabel.font = FONT(14);
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:titleLabel];
        
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        bgView.userInteractionEnabled = YES;
        [bgView addGestureRecognizer:tap];
        
    }
    
    UIView *lastView = [self.scroll viewWithTag:titles.count - 1];
    self.scroll.contentSize = CGSizeMake(0, lastView.bottom + 20);
}
- (void)tapAction:(UITapGestureRecognizer *)tap {
    if (!BY_USER) {
        ByUILoginVC *vc = [[ByUILoginVC alloc] init];
        ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:vc];
        [self presentViewController:navi animated:YES completion:nil];
        return;
    }
    switch (tap.view.tag) {
        case 0:{
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_dxe.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"我是店长";
            [self by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 1:
        {
            NSLog(@"0");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_shop.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"联盟商家";
            [self by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 2:
        {
            NSLog(@"1");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_person.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"创业伙伴";
            [self by_normalPush:webVC hasNavi:YES];

        }
            break;
        case 3:
        {
            NSLog(@"2");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_city.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"城市服务中心";
            [self by_normalPush:webVC hasNavi:YES];
        }
            break;
        case 4:
        {
            NSLog(@"3");
            ByWebViewController *webVC = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@extension/index_province.html?uid=%@&pwd=%@",BOYE_WEB_BASE_URL,BY_USER.uid,BY_USER.password]];
            webVC.title = @"省管理中心";
            [self by_normalPush:webVC hasNavi:YES];
        }
            break;
            
        default:
            break;
    }
}






@end
